package cn.iocoder.yudao.module.member.controller.app.bankaccountinfo;


import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.member.controller.admin.bankaccountinfo.vo.BankAccountInfoRespVO;
import cn.iocoder.yudao.module.member.controller.admin.bankaccountinfo.vo.BankAccountInfoSaveReqVO;
import cn.iocoder.yudao.module.member.convert.bankinfo.BankAccountInfoConvert;
import cn.iocoder.yudao.module.member.dal.dataobject.bankaccountinfo.BankAccountInfoDO;
import cn.iocoder.yudao.module.member.service.bankaccountinfo.BankAccountInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

@Tag(name = "管理后台 - 用户转账信息")
@RestController
@RequestMapping("/member/bank-account-info")
@Validated
public class AppBankAccountInfoController {

    @Resource
    private BankAccountInfoService bankAccountInfoService;

    @PostMapping("/create")
    @Operation(summary = "创建用户转账信息")
    public CommonResult<Long> createBankAccountInfo(@Valid @RequestBody BankAccountInfoSaveReqVO createReqVO) {
        return success(bankAccountInfoService.createBankAccountInfo(getLoginUserId(), createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新用户转账信息")
    public CommonResult<Boolean> updateBankAccountInfo(@Valid @RequestBody BankAccountInfoSaveReqVO updateReqVO) {
        bankAccountInfoService.updateBankAccountInfo(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除用户转账信息")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteBankAccountInfo(@RequestParam("id") Long id) {
        bankAccountInfoService.deleteBankAccountInfo(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得用户转账信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<BankAccountInfoRespVO> getBankAccountInfo(@RequestParam("id") Long id) {
        BankAccountInfoDO bankAccountInfo = bankAccountInfoService.getBankAccountInfo(id);
        return success(BeanUtils.toBean(bankAccountInfo, BankAccountInfoRespVO.class));
    }

    @GetMapping("/list")
    @Operation(summary = "获得收款人列表")
    public CommonResult<List<BankAccountInfoRespVO>> getBankAccountInfoList() {
        List<BankAccountInfoDO> list = bankAccountInfoService.getBankAccountInfoList(getLoginUserId());
        return success(BankAccountInfoConvert.INSTANCE.convert(list));
    }

}